<?php
/**
 * This file is part of webman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author    walkor<walkor@workerman.net>
 * @copyright walkor<walkor@workerman.net>
 * @link      http://www.workerman.net/
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
 */

use Webman\Route;
// 路由不存在时提示
Route::fallback(function () {
    return (new \App\controller\ApiController())::error('无效的请求');
});

Route::add(['GET', 'OPTIONS'], '/', [app\controller\IndexController::class, 'index']);
// 后台入口
Route::add(['GET', 'OPTIONS'], '/admin', [plugin\admin\app\controller\IndexController::class, 'index']);
Route::add(['GET', 'OPTIONS'], '/json', [app\controller\IndexController::class, 'json']);

Route::group('/api', function () {
    // 上传图片
    Route::any('/upload/image', [app\controller\Upload::class, 'upload']);
    // 获取资讯列表
    Route::any('/news/list', [app\controller\news\News::class, 'newsList']);
    // 资讯详情
    Route::any('/new/detail', [app\controller\news\News::class, 'newDetail']);
    // 订阅
    Route::any('/user/subscrip', [app\controller\news\Subscription::class, 'setSubscrip']);

    // 问答列表
    Route::any('/ask/lists', [app\controller\problem\AcProblem::class, 'lists']);

    // firebase设置用户设备token
    Route::any('/fcm/token', [app\controller\message\FcmMessage::class, 'fcmToken']);

    // 推送消息
    Route::any('/push/msg', [app\controller\message\FcmMessage::class, 'cloudMessage']);
    // 订阅主题
    Route::any('/subscribe/topic', [app\controller\message\FcmMessage::class, 'addTopic']);
    // 查找订阅的主题
    Route::any('/find/topics', [app\controller\message\FcmMessage::class, 'getFindTopics']);
    // 向主题发送消息
    Route::any('/send/topic', [app\controller\message\FcmMessage::class, 'sendTopicMsg']);
    // 取消订阅主题
    Route::any('/unsubscribe/topic', [app\controller\message\FcmMessage::class, 'unDelTopic']);
    // 测试验证token
    Route::any('/vali/token', [app\controller\message\FcmMessage::class, 'valiToken']);
    // 定时任务,是否有订阅主题
    Route::get('/check/tokenForTopic', [app\controller\message\FcmMessage::class, 'checkTokenForTopic']);
    // 定时任务,订阅查询toekn是否有效
    Route::get('/check/token', [app\controller\message\FcmMessage::class, 'checkUserToken']);

    /*
     * 验证用户登录
     */
    Route::group('/', function () {
//        // 获取用户信息
//        Route::add(['POST', 'OPTIONS'], 'user/info', [app\controller\user\UserController::class, 'getUser']);
//        // 用户退出
//        Route::add(['POST', 'OPTIONS'], 'sign/out', [app\controller\user\UserController::class, 'signOut']);


    })->middleware([
        App\middleware\AuthCheck::class,
    ]);

    /*
     * 验证登录并防重复提交操作
     */
    Route::group('/', function () {
        // 创建申请店铺
//        Route::add(['POST', 'OPTIONS'], 'apply/shop', [app\controller\good\ShopController::class, 'createShop']);
//        // 添加商品
//        Route::add(['POST', 'OPTIONS'], 'add/good', [app\controller\good\GoodsController::class, 'addGoods']);
//        // 添加到购物车
//        Route::add(['POST', 'OPTIONS'], 'add/cart', [app\controller\good\CartController::class, 'addCart']);


    })->middleware([
        App\middleware\AuthCheck::class,
        App\middleware\AuthRequest::class,
    ]);
});

// 关闭自动路由
Route::disableDefaultRoute();





